package com.grandbroad.eim.ui.activities;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.easy.west.westclient.api.login.bean.User;
import com.grandbroad.eim.R;
import com.grandbroad.eim.adapter.VipCardAdpter;
import com.grandbroad.eim.base.BaseActivity;
import com.grandbroad.eim.entry.OrderBean;
import com.grandbroad.eim.entry.VipBean;
import com.grandbroad.eim.utils.CacheUtils;
import com.grandbroad.eim.wedgit.CameraPopupWindow;
import com.grandbroad.eim.wedgit.VipPopupWindow;
import com.grandbroad.eim.wxapi.WXPayEntryActivity;

import org.xutils.x;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * VIP购买中心
 */
public class VipActivity extends BaseActivity {


    @BindView(R.id.img_btn_back)
    ImageView imgBtnBack;
    @BindView(R.id.img_user_avatar)
    ImageView tvUserAvatar;
    @BindView(R.id.tv_user_name)
    TextView tvUserName;
    @BindView(R.id.tv_vip_state)
    TextView tvVipState;
    @BindView(R.id.grid_vip_card)
    GridView gridVipCard;
    //vipcard适配器
    private VipCardAdpter cardAdpter;
    //底部弹出popwindow
    private VipPopupWindow popupWindow;
    private User user;
    @Override
    protected void initview() {
        tvUserName.setText(user.getName());
        x.image().bind(tvUserAvatar,user.getAvatar());
        cardAdpter = new VipCardAdpter();
        gridVipCard.setAdapter(cardAdpter);
        //初始化事件
        initsesstion();
    }

    private void initsesstion() {
        setBackBtn(imgBtnBack);
        //card_点击事件
        gridVipCard.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
               VipBean vipBean = (VipBean) cardAdpter.getItem(position);
               cardAdpter.setSelectPostion(position);
               popupWindow.setBean(vipBean);
               popupWindow.showAtLocation(R.layout.activity_vip);

            }
        });
    }

    @Override
    protected void initdata() {
        user = CacheUtils.getUser();
        popupWindow = new VipPopupWindow(this);
        popupWindow.setBottomItemClickListener(new VipPopupWindow.onBottomItemClickListener() {
            @Override
            public void click(View view,VipBean vipBean) {
                VipBean vipBean1 = popupWindow.getVipBean();
                switch (view.getId())
                {
                    
                    case R.id.tv_vip_price:
                        //点击了

                        break;
                    case R.id.pay_now:
                        //点击了
                        Bundle bundle = new Bundle();
                        OrderBean orderBean = new OrderBean();
                        orderBean.setDescription(vipBean1.getTime()+"会员");
                        orderBean.setTotalAmount(vipBean1.getNow_price()+"");
                        bundle.putSerializable("bean",orderBean);
                        startActivityWithBundle(PayActivity.class,false,bundle);
                        break;
                }
            }
        });
    }

    @Override
    protected int setlayout() {
        return R.layout.activity_vip;
    }


}
